const mysql = require('mysql');
const conf = require('../conf/db');

const con = mysql.createConnection({
    ...conf.mysql
});

con.connect();

function exec(sql) {
    return new Promise((resolve, reject) => {
        con.query(sql, (err, result) => {
            if (err) {
                reject(err);
                return
            }
            resolve(result);
            console.log("执行完毕！");
        })
    })
}

module.exports = {
    exec,
    escape: mysql.escape
}